package com.crm.business.crm.service;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.crm.common.CrmModel;
import com.crm.common.crm.entity.BO.*;
import com.crm.common.crm.entity.PO.BillCrmStudentPool;
import com.crm.common.crm.entity.PO.CrmContract;
import com.crm.common.crm.entity.PO.CrmReceivablesPlan;
import com.crm.common.crm.entity.VO.CrmInfoNumVO;
import com.crm.common.crm.entity.VO.CrmMembersSelectVO;
import com.crm.common.crm.entity.VO.CrmModelFiledVO;
import com.crm.common.ka.core.entity.BasePage;
import com.crm.common.ka.core.feign.crm.entity.*;
import com.crm.common.crm.entity.BO.CrmSearchBO;
import com.crm.business.servlet.BaseService;
import com.crm.common.ka.core.servlet.upload.FileEntity;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同表 服务类
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-05-27
 */
public interface ICrmContractService extends BaseService<CrmContract> {

    /**
     * 查询字段配置
     *
     * @param id 主键ID
     * @return data
     */
    public List<CrmModelFiledVO> queryField(Integer id);

    /**
     * 分页查询
     *
     * @param search
     * @return
     */
    public BasePage<Map<String, Object>> queryPageList(@RequestBody CrmSearchBO search);


    /**
     * 分页账单池
     * @param search
     * @return
     */
    public BasePage<Map<String, Object>> queryPageListBill(@RequestBody CrmSearchBO search);

    /**
     * 查询字段配置
     *
     * @param id 主键ID
     * @return data
     */
    public CrmModel queryById(Integer id);

    /**
     * 保存或新增信息
     *
     * @param crmModel model
     */
    public void addOrUpdate(CrmContractSaveBO crmModel);

    /**
     * 删除合同数据
     *
     * @param ids ids
     */
    public void deleteByIds(List<Integer> ids);

    /**
     * 修改合同负责人
     *
     * @param changOwnerUserBO       data
     */
    public void changeOwnerUser(CrmBusinessChangOwnerUserBO changOwnerUserBO);

    /**
     * 修改合同讲师负责人
     * @param ownerUserBO
     */
    public void changeTeacherUser(CrmChangeOwnerUserBO ownerUserBO);

    /**
     * 全部导出
     *
     * @param response resp
     * @param search   搜索对象
     */
    public void exportExcel(HttpServletResponse response, CrmSearchBO search);


    /**
     * 获取团队成员
     * @param contractId 合同ID
     * @return data
     */
    public List<CrmMembersSelectVO> getMembers(Integer contractId);

    /**
     * 添加团队成员
     * @param crmMemberSaveBO data
     */
    public void addMember(CrmMemberSaveBO crmMemberSaveBO);

    /**
     * 删除团队成员
     * @param crmMemberSaveBO data
     */
    public void deleteMember(CrmMemberSaveBO crmMemberSaveBO);

    /**
     * 退出团队
     * @param contractId 合同ID
     */
    public void exitTeam(Integer contractId);

    /**
     * 查询详情信息
     * @param contractId 合同ID
     * @return data
     */
    public List<CrmModelFiledVO> information(Integer contractId);

    /**
     * 查询产品通过合同ID
     * @param crmRelationPageBO 合同ID
     * @return data
     */
    public JSONObject queryProductListByContractId(CrmRelationPageBO crmRelationPageBO);

    /**
     * 查询文件数量
     *
     * @param contractId id
     * @return data
     */
    public CrmInfoNumVO num(Integer contractId);

    /**
     * 查询文件列表
     * @param contractId id
     * @return file
     */
    public List<FileEntity> queryFileList(Integer contractId);

    /**
     * 查询回款计划通过合同ID
     * @param crmRelationPageBO 合同ID
     * @return data
     */
    public BasePage<CrmReceivablesPlan> queryReceivablesPlanListByContractId(CrmRelationPageBO crmRelationPageBO);

    public List<SimpleCrmEntity> querySimpleEntity(List<Integer> ids);

    String getContractName(int contractId);

    void updateInformation(CrmUpdateInformationBO updateInformationBO);

    BasePage<JSONObject> queryListByContractId(CrmRelationPageBO crmRelationPageBO);

    List<CrmReceivablesPlan> queryReceivablesPlansByContractId(Integer contractId, Integer receivablesId);

    BasePage<JSONObject> queryReturnVisit(CrmRelationPageBO crmRelationPageBO);

    void contractDiscard(Integer contractId);

    List<String> endContract(CrmEventBO crmEventBO);

    List<String> receiveContract(CrmEventBO crmEventBO);

    BasePage<Map<String, Object>> eventContractPageList(QueryEventCrmPageBO eventCrmPageBO);

    /**
     * 根据产品ID查询合同
     * @param biParams 参数
     * @return data
     */
    public BasePage<Map<String, Object>> queryListByProductId(BiParams biParams);

    public String generateNo(LocalDate date);

    /**
     * 大额数量
     * @return
     */
    Integer largeAmountNum(String laiyuan, String qishu);

    /**
     * 大额成交量，大额成交金额
     * @param laiyuan
     * @param qishu
     * @return
     */
    Map<String, Object> bigDealSum(String laiyuan, String qishu);

    /**
     * 根据客户Id查询合同信息
     * @param customerId 客户Id
     * @return 合同信息集合
     */
    String queryContractByCustomerId(Integer customerId);

    CrmContract queryContractById(@Param("contractId") Integer contractId);

    public CrmContract queryContractByNum(String num);


    /**
     * 领取账单
     * @param poolChangeUserBO
     */
    void changeUser(CrmBillOrderPoolChangeUserBO poolChangeUserBO);

    public void lingQuOrder(Integer id, CrmBillOrderPoolChangeUserBO poolChangeUserBO, BillCrmStudentPool studentPool);

    /**
     * 分配账单
     * @param poolChangeUserBO
     */
    void allocationOrderPoolUser(CrmBillOrderPoolChangeUserBO poolChangeUserBO);

    /**
     * 分配账单
     * @param id
     * @param poolChangeUserBO
     */
    public void distributionOrder(Integer id, CrmBillOrderPoolChangeUserBO poolChangeUserBO, BillCrmStudentPool studentPool);

    /**
     * 账单恢复领取
     * @param userBO
     */
    public void restoreReceive(CrmChangeOwnerUserBO userBO);

    public void restoreReceiveOrder(Integer id, Date expireTime);

    /**
     * 账单置为过期
     */
    public void expireOrder();

    /**
     * 根据VIP学员信息查询审核通过合同
     * @param studentId
     * @return
     */
    public CrmContract queryContractByStudentId(Integer studentId);

    /**
     * 根据学员信息查询审核通过合同
     * @param customerId
     * @return
     */
    public List<CrmContract> queryContractDataByCustomerId(Integer customerId);
}
